package com.ruoyi.service.impl;



import com.ruoyi.mappers.OrderMapper;
import com.ruoyi.pojo.TOrderDo;
import com.ruoyi.service.IOrderService;
import com.ruoyi.vo.OrderQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;


import java.util.List;



@Service
public class OrderServiceImpl implements IOrderService {

    @Autowired
    public OrderMapper orderMapper;

    @Override
    public List<TOrderDo> getAllOrderList(OrderQueryVo orderQueryVo) {
        return orderMapper.getAllOrderList(orderQueryVo);
    }

    @Override
    public int addOrder(TOrderDo tOrderDo) {

        if(tOrderDo.getOrderStatus()==null){
            tOrderDo.setOrderStatus("1");
        }
        try {
            return orderMapper.addOrder(tOrderDo);
        } catch (DataIntegrityViolationException e) {
            // 处理外键约束异常
            if (e.getCause() instanceof java.sql.SQLIntegrityConstraintViolationException) {
                //System.err.println("插入失败，违反外键约束: " + e.getMessage());
                // 可以根据业务需求进行其他处理，如抛出自定义异常
                throw new RuntimeException("插入失败，请检查用户ID,司机ID,车辆ID,用户优惠券ID是否存在", e);
            } else {
               // System.err.println("插入失败，发生其他数据完整性异常: " + e.getMessage());
                throw e;
            }
        }

    }

    @Override
    public int updateTOrder(TOrderDo tOrderDo) {
        return orderMapper.updateTOrder(tOrderDo);
    }

    @Override
    public int deleteTOrderById(Long id) {
        return orderMapper.deleteTOrderById(id);
    }

    @Override
    public TOrderDo selectTOrderVo(Long id) {
        return orderMapper.selectTOrderVo(id);
    }

    @Override
    public int deleteTOrderByIds(Long[] ids) {
        int i = orderMapper.deletePlatformRevenueByOrderIds(ids);
        return orderMapper.deleteTOrderByIds(ids);
    }

    @Override
    public List<TOrderDo> selectOrderVoById(Long id, String field) {
        return orderMapper.selectOrderVoById(id, field);
    }


}
